/**
*      author: Y_Yao
*      created: 2024-10-28 17:12:51
**/

#include<bits/stdc++.h>

using namespace std;
#define int LL
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 100 + 7;
int n;


struct node{
    int w,h;
};

bool cmp(node x,node y)
{
    return x.h > y.h;   
}

node a[N];

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i].w >> a[i].h;
    }

    sort(a + 1,a + n + 1,cmp);

    int ret = 0;
    ret += (a[1].h + a[1].w) * 2;
    int maxw = a[1].w;
    for(int i = 2;i <= n;i++)
    {
        if(a[i].w > maxw)
        {
            ret += (a[i].w - maxw) * 2;
            maxw = a[i].w;
        }
    }

    cout << ret << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}